﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Guline.Hoster.Controllers
{
    public class HostPackagesController : BaseController
    {
        //
        // GET: /HostPackages/
        public ActionResult jsonList()
        {
            return Json(this.db.HostPackages,JsonRequestBehavior.AllowGet);
        }

        public ActionResult Index()
        {
            return View(this.db.HostPackages);
        }
        public ActionResult Create()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Create(Guline.HosterModels.Object.HostPackage model)
        {
            if (ModelState.IsValid)
            {
                this.db.HostPackages.Add(model);
                this.db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View();
        }
        public ActionResult Edit(int ID)
        {
            var host = db.HostPackages.Where(m => m.ID == ID).FirstOrDefault();
            return View(host);
        }
        [HttpPost]
        public ActionResult Edit(Guline.HosterModels.Object.HostPackage model)
        {
            if (ModelState.IsValid)
            {
             
                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View();
        }

        public ActionResult Delete(int HostID)
        {
            var host = db.HostPackages.Where(m => m.ID == HostID).FirstOrDefault();
            db.HostPackages.Remove(host);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        public ActionResult editStatus(int HostID)
        {
            var host = db.HostPackages.Where(m => m.ID == HostID).FirstOrDefault();
            if(host.Status==0)
            {
                host.Status = 1;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            else
            {
                host.Status = 0;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
        }

    }
}
